package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.OrderSetting;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface OrderSettingMapper extends BaseMapper<OrderSetting> {

    @Select("SELECT tor.ORDERDATE,tor.NUMBER,tor.RESERVATIONS " +
            "FROM t_ordersetting tor " +
            "WHERE ORDERDATE " +
            "BETWEEN #{beginDate} " +
            "AND #{endDate}")
    List<OrderSetting> selectOrderSettingByYearAndMonth(@Param("beginDate") String beginDate, @Param("endDate") String endDate);

    @Update("update t_ordersetting set number=#{number} where orderdate=#{settingDay}")
    Boolean updateOrdersettingNumberBySettingData(@Param("number") int number, @Param("settingDay") String settingDay);

    @Select("select count(1) from t_ordersetting where number>RESERVATIONS and orderdate=#{orderDate}")
    int selectOrdersettingInfoByOrderDate(@Param("orderDate") String orderDate);

    @Update("update t_ordersetting set RESERVATIONS=RESERVATIONS+1 where orderdate=#{orderDate}")
    void updateOrdersettingInfoByOrderDate(@Param("orderDate") String orderDate);

    @Delete("DELETE FROM t_ordersetting " +
            "WHERE ORDERDATE <= #{date}")
    void cleanOrderSettingByDate(String date);
}
